1. Field of the Invention
Embodiments of the present invention generally relate to condition codes for and, more specifically, to the use and evaluation of condition tests for non-numeric values.
2. Description of the Related Art
Conventionally condition codes are used in computer programs to store the result of numeric comparisons for later use in determining control flow, in particular to determine which additional computations to perform. Two bits are used to represent three condition codes values indicating whether the comparison output value is positive, zero, or negative. Eight condition tests may be evaluated for a condition code value to produce a true or false result. Six of the eight condition tests are less than (LT), equal (EQ), greater than (GT), less than or equal (LE), greater than or equal (GE), and not equal (NE) representing all relationships between a condition code value and zero. The other two condition tests are always (TR) and never (FL).
The IEEE (Institute of Electronics and Electrical Engineers) has defined a particular format for representing floating point numbers with non-numeric values, not a number (NaN). A NaN does not have an order relative to numeric values, and therefore, can yield unexpected results when used to produce a condition code value or as the input for a condition test. Seven of the eight condition tests evaluate to FALSE when a NaN is present, and the remaining test, the TR test evaluates to TRUE. Because of this, the negation of an ordered test does not result in a negated result when a NaN is present, i.e., GT and LE both evaluate to FALSE.
When an “if” statement is compiled the program code used to represent the “if” statement may use condition codes and a negated condition test. For example, the “if” statement “if A>B, then x=0” may be represented by the code sequence shown in TABLE 1.
TABLE 1COMP cc, A, BBRANCH cc.LE, DONEX = 0DONE:COMP sets the condition code, cc to the result of a comparison between A and B. Specifically when A is greater than B cc=positive, when A is equal to B cc=zero, and when A is less than B cc=negative. It is possible to use an addition or a subtraction operation to produce the condition code. Rather than using the GT test, the LE test is used to “jump over” the x=0 code that should be executed when A>B is true.
Unfortunately, when either A or B is a NaN, the condition code value cannot be reliably determined since different processors may produce different condition code values for a NaN. Therefore, x=0 may be executed when either A or B is a NaN even though the desired result is execute x=0 only when A>B.
Accordingly, there is a desire to use condition codes when non-numeric values may be present and produce deterministic results.